package com.kgc.airquality.controller;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.github.pagehelper.PageInfo;
import com.kgc.airquality.pojo.Airqualityindex;
import com.kgc.airquality.pojo.ResultEntity;
import com.kgc.airquality.service.airqualityindexService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
public class airqualityindexController {
    @Resource
    airqualityindexService airqualityindexServices;
    @RequestMapping("/sele")
      public ResultEntity<PageInfo<Airqualityindex>> seles(
          @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
          @RequestParam(value = "districtId",required = false,defaultValue = "0") Integer districtId
    )  {
        PageInfo<Airqualityindex> sele = airqualityindexServices.sele(pageNum, districtId);
      return  ResultEntity.successWithoutData(sele);
    }


    /*删除*/
    @RequestMapping("/deleByid")
    public ResultEntity<String> deled(Integer id){
try {
Integer integer=airqualityindexServices.delete(id);
return  ResultEntity.successWithoutData(integer+"");
}catch (Exception ex){
return ResultEntity.failed(ex.getMessage());
}
    }


/*save*/
    @RequestMapping("/saveEntry")
        public ResultEntity<Integer> save(@RequestBody Airqualityindex airqualityindex){
Integer integer=null;
airqualityindex.setLastmodifytime(new Date());
        if (airqualityindex.getId()==null){
            /*添加*/
            airqualityindexServices.add(airqualityindex);

        }else {
            //修改
             airqualityindexServices.update(airqualityindex);
        }

        return  ResultEntity.successWithoutData(integer);

    }

    /*根据id查询*/
    @RequestMapping("/getEntryById")
    public  ResultEntity<Airqualityindex>  getByid(Integer id){
        Airqualityindex airqualityindex = airqualityindexServices.selectByid(id);
        return  ResultEntity.successWithoutData(airqualityindex);
    }
}
